Only raise error within union_relations
for build/run sub-commands
#607
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a:
All pull requests from community contributors should target the
main
branch (default).Description & motivation
Fixes #606
Thanks to @erika-e for reporting the issue with
dbt_utils.union_relations
on dbt Cloud and @jeremyyeo for figuring out what was happening and how to solve it.Based on the description in #606, I'm guessing slim CI or something similar was being used. Regardless, I think we have a fix that will support other use-cases too, like SQLFluff.
Checklist
Implementation
I considered several variations for the implementation.
Options for the boolean logic
flags.WHICH
isn't very well documented, but it identifies the dbt subcommand that is executing. It looks like it is planned to be renamed in the future.We know from Erika's error report that the problem is arising during
'generate'
, but it raises the question if more subcommands should be protected from this specific error too.flags.WHICH != 'generate'
flags.WHICH not in ['generate']
flags.WHICH not in ['compile', 'generate']
flags.WHICH in ['run', 'build']
flags.WHICH in ['test', 'run', 'build']
I chose 4. as the most targeted since we know that we want
run
andbuild
to raise an error, but the rest of the commands might be debatable.Options for readability
Chose 1. as a balance of clarity and brevity.
Options for where to place the boolean logic
{% if dbt_command in ['run', 'build'] and (include | length > 0 or exclude | length > 0) and not column_superset.keys() %}
{% if dbt_command in ['run', 'build'] and not column_superset.keys() %}
{% if dbt_command in ['run', 'build'] %}
...{%- endif -%}
{% if dbt_command in ['run', 'build'] %}
I'm feeling too risk averse for 2. (especially given #509 as the response to #505) 😅 But I do think 2. would work based on what I've seen so far.
Opted for 3. because it guards all the error-raising logic in a tidy wrapper and yields the most readable diff.
Future hopes
The
union_relations
macro is really cool because it handles the complex logic to union two relations that don't necessarily have the same columns. But it's grown organically and been fragile as a result (see here for a partial list of bug reports and fixes).I'd love to see us: